<?php
function retriveitemsf(){
	$serverpath=$_SERVER['DOCUMENT_ROOT'];
	include_once ($serverpath.'/Classes/Factura.php');
	$serial_factura = file_get_contents('store_factura');
	$factura = unserialize($serial_factura);
	$string =
		 '</table>
		 	<table width="850" border="0" cellpadding="0" cellspacing="0">
		 	<tr>
		    	<td>
		    	CANTIDAD
		    	</td>
		    	<td>
		    	TITULO
		    	</td>
		    	<td>
		    	PRECIO POR UNIDAD
		    	</td>
		    </tr>';
	$subtotal = 0;
	for ($i = 0; $i <= $factura->get_cantitems()-1; $i++) {
		$precio = $factura->arrayitemf[$i]->get_precio()*$factura->arrayitemf[$i]->get_cant();
		$subtotal = $subtotal + $precio;
		$string =  $string.
			'<tr>
		    	<td><br>'
		    	.$factura->arrayitemf[$i]->get_cant().
				'</td>
				<td>'
		    	.$factura->arrayitemf[$i]->get_libroname().
				'</td>
				<td>'
		    	.$factura->arrayitemf[$i]->get_precio().
				'</td>
			  </tr>';
	}
	$string =  $string.
		'<tr>
				<td><br>
				TOTAL:
				</td>
				<td>'
				.$subtotal.
				'</td>
			</tr>';
	return $string;
}

function retriveSection(){
	$serverpath=$_SERVER['DOCUMENT_ROOT'];
	$filename=$serverpath.'/files/sections.txt';
	//$filename="C:/xampp/htdocs/librejo/WEB/files/sections.txt";
	$fp = fopen($filename, "r");
	$string;
	while (!feof($fp)) {
		$line=fgets($fp);
		$linea = '<option>'.$line.'</option>';
		$string = $string.$linea;
	}
	fclose($fp);
	return $string;
}

function searchByCombo(){
    $serverpath=$_SERVER['DOCUMENT_ROOT'];
    include_once ($serverpath.'/Classes/book.php');
	$section=$_POST['select'];
	$searchbook = new Book($id);
	$serialize_searchbook = serialize($searchbook);
	file_put_contents('store_searchbook',$serialize_searchbook);
	header ('Location: modifyItem.php');
}

function retriveComments(){
	$serverpath=$_SERVER['DOCUMENT_ROOT'];
	$searchResult = file_get_contents('store_search');
	//$sectionInfo = unserialize($searchResult);
	$info = explode('|', $sectionInfo);
	$filename=$serverpath."/files/Comments/".$info[0].".txt";
	$fp = fopen($filename, "r");
	while (!feof($fp)) {
		$line=fgets($fp);
		$fileComment = explode('|',$line);
		$comment[]=$fileComment[1];
	}
	fclose($fp);
	return $comment;
}

?>